using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Resources;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using PluginFrame;

namespace ExperimentRuleEditor
{
	public class EFormula : Form
	{
		private IContainer components;

		private RichTextBox rttext;

		private Button btAddPattern;

		private Button btAddOperator;

		private Button btAddValue;

		private Button btOk;

		private Button btCancel;

		public List<structOperator> m_GLOperator = new List<structOperator>();

		private structOperator m_LOperator = default(structOperator);

		private structOperator m_TLOperator = default(structOperator);

		private int[] m_LSelectIndex = new int[2];

		public string m_TModelSelectionText;

		public string m_TProjectSelectionText;

		public string m_TOperator;

		public string m_TValue;

		private string m_LProjectName;

		private readonly IPcrLogService mPcrLogService;

		protected ResourceManager mResourceManager;

		private int m_LPattern;

		private int m_LTarget;

		private int m_LOperatorSign;

		private string m_LValue;

		public string GetExpressionText
		{
			get
			{
				return rttext.Text;
			}
		}

		public int GetPatternIndex
		{
			get
			{
				return m_LPattern;
			}
		}

		public int GetTargetIndex
		{
			get
			{
				return m_LTarget;
			}
		}

		public int GetOperatorIndex
		{
			get
			{
				return m_LOperatorSign;
			}
		}

		public string GetValueIndex
		{
			get
			{
				return m_LValue;
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExperimentRuleEditor.EFormula));
			this.rttext = new System.Windows.Forms.RichTextBox();
			this.btAddPattern = new System.Windows.Forms.Button();
			this.btAddOperator = new System.Windows.Forms.Button();
			this.btAddValue = new System.Windows.Forms.Button();
			this.btOk = new System.Windows.Forms.Button();
			this.btCancel = new System.Windows.Forms.Button();
			base.SuspendLayout();
			resources.ApplyResources(this.rttext, "rttext");
			this.rttext.Name = "rttext";
			this.rttext.KeyDown += new System.Windows.Forms.KeyEventHandler(rttext_KeyDown);
			this.rttext.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(rttext_MouseDoubleClick);
			this.rttext.MouseClick += new System.Windows.Forms.MouseEventHandler(rttext_MouseClick);
			this.rttext.MouseDown += new System.Windows.Forms.MouseEventHandler(rttext_MouseDown);
			this.rttext.KeyPress += new System.Windows.Forms.KeyPressEventHandler(rttext_KeyPress);
			this.rttext.KeyUp += new System.Windows.Forms.KeyEventHandler(rttext_KeyUp);
			resources.ApplyResources(this.btAddPattern, "btAddPattern");
			this.btAddPattern.Name = "btAddPattern";
			this.btAddPattern.UseVisualStyleBackColor = true;
			this.btAddPattern.Click += new System.EventHandler(btAddPattern_Click);
			resources.ApplyResources(this.btAddOperator, "btAddOperator");
			this.btAddOperator.Name = "btAddOperator";
			this.btAddOperator.UseVisualStyleBackColor = true;
			this.btAddOperator.Click += new System.EventHandler(btAddOperator_Click);
			resources.ApplyResources(this.btAddValue, "btAddValue");
			this.btAddValue.Name = "btAddValue";
			this.btAddValue.UseVisualStyleBackColor = true;
			this.btAddValue.Click += new System.EventHandler(btAddValue_Click);
			resources.ApplyResources(this.btOk, "btOk");
			this.btOk.Name = "btOk";
			this.btOk.UseVisualStyleBackColor = true;
			this.btOk.Click += new System.EventHandler(btOk_Click);
			resources.ApplyResources(this.btCancel, "btCancel");
			this.btCancel.Name = "btCancel";
			this.btCancel.UseVisualStyleBackColor = true;
			this.btCancel.Click += new System.EventHandler(btCancel_Click);
			resources.ApplyResources(this, "$this");
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.Controls.Add(this.btCancel);
			base.Controls.Add(this.btOk);
			base.Controls.Add(this.btAddValue);
			base.Controls.Add(this.btAddOperator);
			base.Controls.Add(this.btAddPattern);
			base.Controls.Add(this.rttext);
			base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "EFormula";
			base.ShowIcon = false;
			base.ShowInTaskbar = false;
			base.ResumeLayout(false);
		}

		public EFormula(IApplication app, string mExpression, string mProjectName, int m_Pattern, int m_Target, int m_Operator, string m_Value)
		{
			InitializeComponent();
			m_LPattern = m_Pattern;
			m_LTarget = m_Target;
			m_LOperatorSign = m_Operator;
			m_LValue = m_Value;
			mResourceManager = ResourceManager.CreateFileBasedResourceManager("ExperimentRuleEditor", app.GetResourceFolder() + GetType().Namespace + "\\", null);
			rttext.Text = mExpression;
			m_LProjectName = mProjectName;
			if (mExpression != "")
			{
				string[] array = mExpression.Split(' ');
				for (int i = 0; i < array.Length; i++)
				{
					m_LOperator = default(structOperator);
					m_LOperator.operatorvalue = array[i];
					if (i == 0)
					{
						m_LOperator.start = 0;
					}
					else
					{
						m_LOperator.start = m_GLOperator[i - 1].end + 1;
					}
					m_LOperator.end = m_LOperator.start + array[i].Length;
					if (array[i] == "+" || array[i] == "-" || array[i] == "*" || array[i] == "/")
					{
						m_LOperator.type = 2;
					}
					else if (IsNumeric(array[i]))
					{
						m_LOperator.type = 3;
					}
					else
					{
						m_LOperator.type = 1;
					}
					m_GLOperator.Add(m_LOperator);
				}
				if (m_GLOperator.Count > 0)
				{
					rttext.SelectionStart = m_GLOperator[m_GLOperator.Count - 1].start;
					rttext.SelectionLength = m_GLOperator[m_GLOperator.Count - 1].end - rttext.SelectionStart;
				}
			}
			rttext.HideSelection = false;
			mPcrLogService = (IPcrLogService)app.GetService("PcrLogService");
		}

		private void rttext_MouseClick(object sender, MouseEventArgs e)
		{
			try
			{
				for (int i = 0; i < m_GLOperator.Count; i++)
				{
					if (rttext.SelectionStart <= m_GLOperator[i].end && rttext.SelectionStart >= m_GLOperator[i].start)
					{
						rttext.Select(m_GLOperator[i].start, m_GLOperator[i].end - m_GLOperator[i].start);
						m_LSelectIndex[0] = m_GLOperator[i].end;
						m_LSelectIndex[1] = i;
						break;
					}
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void rttext_KeyPress(object sender, KeyPressEventArgs e)
		{
			try
			{
				if (e.KeyChar == '\b')
				{
					if (m_GLOperator.Count != 0)
					{
						rttext.SelectionStart = m_GLOperator[m_LSelectIndex[1]].start;
						rttext.SelectionLength = m_GLOperator[m_LSelectIndex[1]].end - m_GLOperator[m_LSelectIndex[1]].start;
					}
				}
				else
				{
					e.Handled = true;
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void rttext_KeyDown(object sender, KeyEventArgs e)
		{
			try
			{
				if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back)
				{
					int num = rttext.SelectionStart - 1;
					int num2 = rttext.SelectionLength + 1;
					if (rttext.Text == "")
					{
						return;
					}
					if (num < 0)
					{
						num = 0;
						if (num2 > rttext.Text.Length)
						{
							num2 = rttext.Text.Length;
						}
					}
					string text = rttext.Text.Remove(num, num2);
					rttext.Text = text;
					if (m_LSelectIndex[1] == 0 && m_LSelectIndex[0] != 0)
					{
						for (int i = m_LSelectIndex[1] + 1; i < m_GLOperator.Count; i++)
						{
							m_TLOperator.start = m_GLOperator[i].start - num2;
							m_TLOperator.end = m_GLOperator[i].end - num2;
							m_TLOperator.operatorvalue = m_GLOperator[i].operatorvalue;
							m_TLOperator.type = m_GLOperator[i].type;
							m_GLOperator.RemoveAt(i);
							m_GLOperator.Insert(i, m_TLOperator);
						}
						m_GLOperator.RemoveAt(m_LSelectIndex[1]);
						if (m_GLOperator.Count > 0)
						{
							m_LSelectIndex[0] = m_GLOperator[0].end;
						}
						else
						{
							m_LSelectIndex[0] = 0;
						}
					}
					else if (m_LSelectIndex[1] == 0 && m_LSelectIndex[0] == 0)
					{
						if (m_GLOperator.Count > 1)
						{
							m_LSelectIndex[0] = m_GLOperator[m_GLOperator.Count - 2].end;
							m_LSelectIndex[1] = m_GLOperator.Count - 2;
						}
						else
						{
							m_LSelectIndex[0] = 0;
							m_LSelectIndex[1] = 0;
						}
						m_GLOperator.RemoveAt(m_GLOperator.Count - 1);
					}
					else
					{
						for (int j = m_LSelectIndex[1] + 1; j < m_GLOperator.Count; j++)
						{
							m_TLOperator.start = m_GLOperator[j].start - num2;
							m_TLOperator.end = m_GLOperator[j].end - num2;
							m_TLOperator.operatorvalue = m_GLOperator[j].operatorvalue;
							m_TLOperator.type = m_GLOperator[j].type;
							m_GLOperator.RemoveAt(j);
							m_GLOperator.Insert(j, m_TLOperator);
						}
						m_LSelectIndex[0] = m_GLOperator[m_LSelectIndex[1] - 1].end;
						m_GLOperator.RemoveAt(m_LSelectIndex[1]);
						m_LSelectIndex[1] = m_LSelectIndex[1] - 1;
					}
				}
				else
				{
					if (e.KeyCode == Keys.Left && rttext.SelectionStart > 1)
					{
						rttext.SelectionStart -= 1;
					}
					if (e.KeyCode == Keys.Right && rttext.SelectionStart < m_GLOperator[m_GLOperator.Count - 1].end)
					{
						rttext.SelectionStart += 1;
					}
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void rttext_KeyUp(object sender, KeyEventArgs e)
		{
			try
			{
				for (int i = 0; i < m_GLOperator.Count; i++)
				{
					if (rttext.SelectionStart <= m_GLOperator[i].end && rttext.SelectionStart >= m_GLOperator[i].start)
					{
						rttext.Select(m_GLOperator[i].start, m_GLOperator[i].end - m_GLOperator[i].start);
						m_LSelectIndex[0] = m_GLOperator[i].end;
						m_LSelectIndex[1] = i;
						break;
					}
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void rttext_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			try
			{
				for (int i = 0; i < m_GLOperator.Count; i++)
				{
					if (rttext.SelectionStart <= m_GLOperator[i].end && rttext.SelectionStart >= m_GLOperator[i].start)
					{
						rttext.Select(m_GLOperator[i].start, m_GLOperator[i].end - m_GLOperator[i].start);
						m_LSelectIndex[0] = m_GLOperator[i].end;
						m_LSelectIndex[1] = i;
						break;
					}
				}
				if (m_GLOperator.Count != 0)
				{
					if (m_GLOperator[m_LSelectIndex[1]].type == 1)
					{
						string selectedText = rttext.SelectedText;
						string[] array = selectedText.Split('(', ')');
						m_TModelSelectionText = array[0];
						m_TProjectSelectionText = array[1];
						DisplayDataModel(m_TModelSelectionText, m_TProjectSelectionText, 1);
					}
					else if (m_GLOperator[m_LSelectIndex[1]].type == 2)
					{
						m_TOperator = rttext.SelectedText;
						DisplayOperator(m_TOperator, 1);
					}
					else if (m_GLOperator[m_LSelectIndex[1]].type == 3)
					{
						m_TValue = rttext.SelectedText;
						DisplayValue(m_TValue, 1);
					}
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void DisplayDataModel(string mModel, string mProject, int mDisplayModel)
		{
			EModel eModel = new EModel(mModel, mProject, m_LProjectName, m_LPattern, m_LTarget);
			if (eModel.ShowDialog() != DialogResult.OK)
			{
				return;
			}
			m_TModelSelectionText = eModel.GetModelText;
			m_TProjectSelectionText = eModel.GetProjectText;
			m_LPattern = eModel.GetPatternIndex;
			m_LTarget = eModel.GetTargetIndex;
			if (mDisplayModel == 0)
			{
				string text = eModel.m_Lmodel + "(" + eModel.m_LProject + ")";
				rttext.Focus();
				if (m_LSelectIndex[0] != 0)
				{
					string text2 = rttext.Text;
					string text3 = null;
					if (text2.Length == 0)
					{
						text3 = text;
					}
					else if (m_LSelectIndex[0] >= m_GLOperator[m_GLOperator.Count - 1].end)
					{
						text3 = text2 + " " + text;
					}
					else
					{
						string value = text + " ";
						text3 = text2.Insert(m_LSelectIndex[0] + 1, value);
					}
					rttext.Text = text3;
				}
				else if (rttext.Text == "")
				{
					rttext.Text += text;
				}
				else
				{
					rttext.Text = rttext.Text + " " + text;
				}
				m_LOperator = default(structOperator);
				if (m_GLOperator.Count == 0)
				{
					m_LOperator.start = 0;
					m_LOperator.end = text.Length;
					m_LOperator.operatorvalue = text;
					m_LOperator.type = 1;
					rttext.SelectionStart = m_LOperator.start;
					rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
					m_GLOperator.Add(m_LOperator);
				}
				else if (m_LSelectIndex[0] != 0)
				{
					m_LOperator.start = m_LSelectIndex[0] + 1;
					m_LOperator.operatorvalue = eModel.m_Lmodel + "(" + eModel.m_LProject + ")";
					m_LOperator.end = m_LOperator.start + m_LOperator.operatorvalue.Length;
					m_LOperator.type = 1;
					for (int i = m_LSelectIndex[1] + 1; i < m_GLOperator.Count; i++)
					{
						m_TLOperator.start = m_GLOperator[i].start + m_LOperator.operatorvalue.Length + 1;
						m_TLOperator.end = m_GLOperator[i].end + m_LOperator.operatorvalue.Length + 1;
						m_TLOperator.operatorvalue = m_GLOperator[i].operatorvalue;
						m_TLOperator.type = m_GLOperator[i].type;
						m_GLOperator.RemoveAt(i);
						m_GLOperator.Insert(i, m_TLOperator);
					}
					if (m_LSelectIndex[1] + 1 > m_GLOperator.Count)
					{
						m_GLOperator.Add(m_LOperator);
						rttext.Select(m_LOperator.start, m_LOperator.end - m_LOperator.start);
						m_LSelectIndex[0] = m_LOperator.end;
						m_LSelectIndex[1] = m_LSelectIndex[1] + 1;
					}
					else
					{
						m_GLOperator.Insert(m_LSelectIndex[1] + 1, m_LOperator);
						rttext.Select(m_LOperator.start, m_LOperator.end - m_LOperator.start);
						m_LSelectIndex[0] = m_LOperator.end;
						m_LSelectIndex[1] = m_LSelectIndex[1] + 1;
					}
				}
				else
				{
					m_LOperator.start = rttext.Text.Length - text.Length;
					m_LOperator.end = m_LOperator.start + text.Length;
					m_LOperator.operatorvalue = text;
					m_LOperator.type = 1;
					rttext.SelectionStart = m_LOperator.start;
					rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
					m_GLOperator.Add(m_LOperator);
				}
			}
			else
			{
				string text4 = eModel.m_Lmodel + "(" + eModel.m_LProject + ")";
				rttext.Focus();
				string text5 = null;
				text5 = ((m_LSelectIndex[0] + 1 <= rttext.Text.Length) ? rttext.Text.Substring(m_LSelectIndex[0] + 1) : "");
				string text6 = rttext.Text.Remove(rttext.SelectionStart);
				if (text5 == "")
				{
					rttext.Text = text6 + text4;
				}
				else
				{
					rttext.Text = text6 + text4 + " " + text5;
				}
				m_LOperator.start = m_GLOperator[m_LSelectIndex[1]].start;
				m_LOperator.operatorvalue = eModel.m_Lmodel + "(" + eModel.m_LProject + ")";
				m_LOperator.end = m_LOperator.start + m_LOperator.operatorvalue.Length;
				m_LOperator.type = 1;
				for (int j = m_LSelectIndex[1] + 1; j < m_GLOperator.Count; j++)
				{
					m_TLOperator.start = m_GLOperator[j - 1].start + m_LOperator.operatorvalue.Length + 1;
					m_TLOperator.end = m_GLOperator[j - 1].end + m_LOperator.operatorvalue.Length + 1;
					m_TLOperator.operatorvalue = m_GLOperator[j].operatorvalue;
					m_TLOperator.type = m_GLOperator[j].type;
					m_GLOperator.RemoveAt(j);
					m_GLOperator.Insert(j, m_TLOperator);
				}
				m_GLOperator.RemoveAt(m_LSelectIndex[1]);
				rttext.SelectionStart = m_LOperator.start;
				rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
				m_LSelectIndex[0] = m_LOperator.end;
				m_LSelectIndex[1] = m_LSelectIndex[1];
				m_GLOperator.Insert(m_LSelectIndex[1], m_LOperator);
			}
		}

		private void DisplayOperator(string mOperator, int mDisplayModel)
		{
			EOperator eOperator = new EOperator(mOperator, m_LOperatorSign);
			if (eOperator.ShowDialog() == DialogResult.OK)
			{
				m_LOperator = default(structOperator);
				string lOperator = eOperator.m_LOperator;
				m_LOperatorSign = eOperator.GetOperatorIndex;
				if (mDisplayModel == 0)
				{
					if (m_LSelectIndex[0] != 0)
					{
						string text = rttext.Text;
						string text2;
						if (m_LSelectIndex[0] >= m_GLOperator[m_GLOperator.Count - 1].end)
						{
							text2 = text + " " + lOperator;
						}
						else
						{
							string value = lOperator + " ";
							text2 = text.Insert(m_LSelectIndex[0] + 1, value);
						}
						rttext.Text = text2;
						m_LOperator.start = m_LSelectIndex[0] + 1;
						m_LOperator.end = m_LOperator.start + eOperator.m_LOperator.Length;
						m_LOperator.operatorvalue = eOperator.m_LOperator;
						rttext.SelectionStart = m_LOperator.start;
						rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
						m_LOperator.type = 2;
						for (int i = m_LSelectIndex[1] + 1; i < m_GLOperator.Count; i++)
						{
							m_TLOperator.start = m_GLOperator[i].start + eOperator.m_LOperator.Length + 1;
							m_TLOperator.end = m_GLOperator[i].end + eOperator.m_LOperator.Length + 1;
							m_TLOperator.operatorvalue = m_GLOperator[i].operatorvalue;
							m_TLOperator.type = m_GLOperator[i].type;
							m_GLOperator.RemoveAt(i);
							m_GLOperator.Insert(i, m_TLOperator);
						}
						if (m_LSelectIndex[1] + 1 > m_GLOperator.Count)
						{
							m_GLOperator.Add(m_LOperator);
							rttext.Select(m_LOperator.start, m_LOperator.end - m_LOperator.start);
							m_LSelectIndex[0] = m_LOperator.end;
							m_LSelectIndex[1] = m_LSelectIndex[1] + 1;
						}
						else
						{
							m_GLOperator.Insert(m_LSelectIndex[1] + 1, m_LOperator);
							rttext.Select(m_LOperator.start, m_LOperator.end - m_LOperator.start);
							m_LSelectIndex[0] = m_LOperator.end;
							m_LSelectIndex[1] = m_LSelectIndex[1] + 1;
						}
					}
					else
					{
						if (rttext.Text == "")
						{
							m_LOperator.start = 0;
						}
						else
						{
							m_LOperator.start = rttext.Text.Length + 1;
						}
						if (rttext.Text == "")
						{
							rttext.Text += lOperator;
						}
						else
						{
							rttext.Text = rttext.Text + " " + lOperator;
						}
						m_LOperator.end = m_LOperator.start + eOperator.m_LOperator.Length;
						m_LOperator.operatorvalue = eOperator.m_LOperator;
						m_LOperator.type = 2;
						rttext.SelectionStart = m_LOperator.start;
						rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
						m_GLOperator.Add(m_LOperator);
					}
				}
				else
				{
					string lOperator2 = eOperator.m_LOperator;
					string text3 = null;
					text3 = ((m_LSelectIndex[0] + 1 <= rttext.Text.Length) ? rttext.Text.Substring(m_LSelectIndex[0] + 1) : "");
					string text4 = rttext.Text.Remove(rttext.SelectionStart);
					if (text3 == "")
					{
						rttext.Text = text4 + lOperator2;
					}
					else
					{
						rttext.Text = text4 + lOperator2 + " " + text3;
					}
					m_LOperator.start = m_GLOperator[m_LSelectIndex[1]].start;
					m_LOperator.operatorvalue = eOperator.m_LOperator;
					m_LOperator.end = m_LOperator.start + m_LOperator.operatorvalue.Length;
					m_LOperator.type = 2;
					for (int j = m_LSelectIndex[1] + 1; j < m_GLOperator.Count; j++)
					{
						m_TLOperator.start = m_GLOperator[j - 1].start + m_LOperator.operatorvalue.Length + 1;
						m_TLOperator.end = m_GLOperator[j - 1].end + m_LOperator.operatorvalue.Length + 1;
						m_TLOperator.operatorvalue = m_GLOperator[j].operatorvalue;
						m_TLOperator.type = m_GLOperator[j].type;
						m_GLOperator.RemoveAt(j);
						m_GLOperator.Insert(j, m_TLOperator);
					}
					m_GLOperator.RemoveAt(m_LSelectIndex[1]);
					rttext.SelectionStart = m_LOperator.start;
					rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
					m_LSelectIndex[0] = m_LOperator.end;
					m_LSelectIndex[1] = m_LSelectIndex[1];
					m_GLOperator.Insert(m_LSelectIndex[1], m_LOperator);
				}
			}
			rttext.Focus();
		}

		private void DisplayValue(string mValue, int mDisplayModel)
		{
			EValue eValue = new EValue(mValue, m_LValue);
			if (eValue.ShowDialog() == DialogResult.OK)
			{
				m_LOperator = default(structOperator);
				string text = (m_LValue = eValue.OperatorValue.ToString());
				if (mDisplayModel == 0)
				{
					if (m_LSelectIndex[0] != 0)
					{
						string text2 = rttext.Text;
						string text3;
						if (m_LSelectIndex[0] >= m_GLOperator[m_GLOperator.Count - 1].end)
						{
							text3 = text2 + " " + text;
						}
						else
						{
							string value = text + " ";
							text3 = text2.Insert(m_LSelectIndex[0] + 1, value);
						}
						rttext.Text = text3;
						m_LOperator.start = m_LSelectIndex[0] + 1;
						m_LOperator.end = m_LOperator.start + eValue.OperatorValue.ToString().Length;
						m_LOperator.operatorvalue = eValue.OperatorValue.ToString();
						m_LOperator.type = 3;
						rttext.SelectionStart = m_LOperator.start;
						rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
						for (int i = m_LSelectIndex[1] + 1; i < m_GLOperator.Count; i++)
						{
							m_TLOperator.start = m_GLOperator[i].start + eValue.OperatorValue.ToString().Length + 1;
							m_TLOperator.end = m_GLOperator[i].end + eValue.OperatorValue.ToString().Length + 1;
							m_TLOperator.operatorvalue = m_GLOperator[i].operatorvalue;
							m_TLOperator.type = m_GLOperator[i].type;
							m_GLOperator.RemoveAt(i);
							m_GLOperator.Insert(i, m_TLOperator);
						}
						if (m_LSelectIndex[1] + 1 > m_GLOperator.Count)
						{
							m_GLOperator.Add(m_LOperator);
							rttext.Select(m_LOperator.start, m_LOperator.end - m_LOperator.start);
							m_LSelectIndex[0] = m_LOperator.end;
							m_LSelectIndex[1] = m_LSelectIndex[1] + 1;
						}
						else
						{
							m_GLOperator.Insert(m_LSelectIndex[1] + 1, m_LOperator);
							rttext.Select(m_LOperator.start, m_LOperator.end - m_LOperator.start);
							m_LSelectIndex[0] = m_LOperator.end;
							m_LSelectIndex[1] = m_LSelectIndex[1] + 1;
						}
					}
					else
					{
						if (rttext.Text == "")
						{
							m_LOperator.start = 0;
						}
						else
						{
							m_LOperator.start = rttext.Text.Length + 1;
						}
						if (rttext.Text == "")
						{
							rttext.Text += text;
						}
						else
						{
							rttext.Text = rttext.Text + " " + text;
						}
						m_LOperator.end = m_LOperator.start + eValue.OperatorValue.ToString().Length;
						m_LOperator.operatorvalue = eValue.OperatorValue.ToString();
						m_LOperator.type = 3;
						rttext.SelectionStart = m_LOperator.start;
						rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
						m_GLOperator.Add(m_LOperator);
					}
				}
				else
				{
					string text4 = eValue.OperatorValue.ToString();
					string text5 = null;
					text5 = ((m_LSelectIndex[0] + 1 <= rttext.Text.Length) ? rttext.Text.Substring(m_LSelectIndex[0] + 1) : "");
					string text6 = rttext.Text.Remove(rttext.SelectionStart);
					if (text5 == "")
					{
						rttext.Text = text6 + text4;
					}
					else
					{
						rttext.Text = text6 + text4 + " " + text5;
					}
					m_LOperator.start = m_GLOperator[m_LSelectIndex[1]].start;
					m_LOperator.operatorvalue = eValue.OperatorValue.ToString();
					m_LOperator.end = m_LOperator.start + m_LOperator.operatorvalue.Length;
					m_LOperator.type = 3;
					for (int j = m_LSelectIndex[1] + 1; j < m_GLOperator.Count; j++)
					{
						m_TLOperator.start = m_GLOperator[j - 1].start + m_LOperator.operatorvalue.Length + 1;
						m_TLOperator.end = m_GLOperator[j - 1].end + m_LOperator.operatorvalue.Length + 1;
						m_TLOperator.operatorvalue = m_GLOperator[j].operatorvalue;
						m_TLOperator.type = m_GLOperator[j].type;
						m_GLOperator.RemoveAt(j);
						m_GLOperator.Insert(j, m_TLOperator);
					}
					m_GLOperator.RemoveAt(m_LSelectIndex[1]);
					rttext.SelectionStart = m_LOperator.start;
					rttext.SelectionLength = m_LOperator.end - m_LOperator.start;
					m_LSelectIndex[0] = m_LOperator.end;
					m_LSelectIndex[1] = m_LSelectIndex[1];
					m_GLOperator.Insert(m_LSelectIndex[1], m_LOperator);
				}
			}
			rttext.Focus();
		}

		private bool IsNumeric(string value)
		{
			return Regex.IsMatch(value, "^[+-]?\\d*[.]?\\d*$");
		}

		private void btOk_Click(object sender, EventArgs e)
		{
			try
			{
				if (m_GLOperator.Count == 0)
				{
					base.DialogResult = DialogResult.OK;
					Close();
					return;
				}
				switch (m_GLOperator[0].operatorvalue)
				{
				case "+":
				case "-":
				case "*":
				case "/":
					rttext.SelectionStart = m_GLOperator[0].start;
					rttext.SelectionLength = m_GLOperator[0].end - m_GLOperator[0].start;
					m_LSelectIndex[0] = m_GLOperator[0].end;
					m_LSelectIndex[1] = 0;
					rttext.Focus();
					MessageBox.Show(mResourceManager.GetString("AfterString") + m_GLOperator[0].operatorvalue + mResourceManager.GetString("StringIsErrorString"), mResourceManager.GetString("ErrorString"));
					return;
				}
				if (m_GLOperator.Count > 1)
				{
					switch (m_GLOperator[m_GLOperator.Count - 1].operatorvalue)
					{
					case "+":
					case "-":
					case "*":
					case "/":
						rttext.SelectionStart = m_GLOperator[m_GLOperator.Count - 1].start;
						rttext.SelectionLength = m_GLOperator[m_GLOperator.Count - 1].end - m_GLOperator[m_GLOperator.Count - 1].start;
						m_LSelectIndex[0] = m_GLOperator[m_GLOperator.Count - 1].end;
						m_LSelectIndex[1] = m_GLOperator.Count - 1;
						rttext.Focus();
						MessageBox.Show(mResourceManager.GetString("AfterString") + m_GLOperator[m_GLOperator.Count - 1].operatorvalue + mResourceManager.GetString("StringIsErrorString"), mResourceManager.GetString("ErrorString"));
						return;
					}
					for (int num = 0; num < m_GLOperator.Count - 1; num += 2)
					{
						switch (m_GLOperator[num].operatorvalue)
						{
						case "+":
						case "-":
						case "*":
						case "/":
							rttext.SelectionStart = m_GLOperator[num - 1].start;
							rttext.SelectionLength = m_GLOperator[num - 1].end - m_GLOperator[num - 1].start;
							m_LSelectIndex[0] = m_GLOperator[num - 1].end;
							m_LSelectIndex[1] = num - 1;
							rttext.Focus();
							MessageBox.Show(mResourceManager.GetString("AfterString") + m_GLOperator[num - 1].operatorvalue + mResourceManager.GetString("StringIsErrorString"), mResourceManager.GetString("ErrorString"));
							return;
						}
						switch (m_GLOperator[num + 1].operatorvalue)
						{
						default:
							rttext.SelectionStart = m_GLOperator[num].start;
							rttext.SelectionLength = m_GLOperator[num].end - m_GLOperator[num].start;
							m_LSelectIndex[0] = m_GLOperator[num].end;
							m_LSelectIndex[1] = num;
							rttext.Focus();
							MessageBox.Show(mResourceManager.GetString("AfterString") + m_GLOperator[num].operatorvalue + mResourceManager.GetString("StringIsErrorString"), mResourceManager.GetString("ErrorString"));
							return;
						case "+":
						case "-":
						case "*":
						case "/":
							break;
						}
					}
				}
				base.DialogResult = DialogResult.OK;
				Close();
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void btCancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void btAddPattern_Click(object sender, EventArgs e)
		{
			try
			{
				DisplayDataModel(m_TModelSelectionText, m_TProjectSelectionText, 0);
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void btAddOperator_Click(object sender, EventArgs e)
		{
			try
			{
				DisplayOperator(m_TOperator, 0);
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void btAddValue_Click(object sender, EventArgs e)
		{
			try
			{
				DisplayValue(m_TValue, 0);
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		private void rttext_MouseDown(object sender, MouseEventArgs e)
		{
		}
	}
}
